import React, { Component } from 'react';
import { Pagination } from 'antd';

export default class MyPagination extends React.Component {
    state = {
        current: 1,
        houseArray: []
    };

    onChange = page => {
        console.log(this.props)
        console.log("点击第" + page + "页");
        this.setState({
            current: page,
            houseArray: []
        });

        fetch('http://127.0.0.1:8000/JSON-server', {
            method: 'post',
            headers: {
                "Content-type": "application/json"
            },
            body: page
        }).then((response) => {
            return response.json()
        }).then((data) => {
            console.log("点击换页收到的数据为" + data)
            this.setState({ houseArray: data })
        }).catch(function (error) {
            console.log(error)
        })
    };

    render() {
        return <div>
            <Pagination {...this.props}
                current={this.state.current}
                onChange={this.onChange}
                total={50}
            />
        </div>
    }
}